package de.lot.action;

import de.lot.model.LearningOutcome;
import de.lot.model.Trait;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

/**
 * TraitHome is for interacting between UI and back-end for Trait component
 *
 * @see Trait
 * @author Stefan Kohler <kohler.stefan@gmail.com>
 */
@Name("traitHome")
public class TraitHome extends EntityHome<Trait> {

    @In(create = true)
    LearningOutcomeHome learningOutcomeHome;

    public void setTraitId(Long id) {
        setId(id);
    }

    public Long getTraitId() {
        return (Long) getId();
    }

    @Override
    protected Trait createInstance() {
        Trait trait = new Trait();
        return trait;
    }

    /**
     * Checks if trait is associated to a learningOutcome
     *
     * @return <code>true</code> if association is available
     *         <code>false</code> if association is NOT available
     */
    public boolean isWired() {
        if (getInstance().getLearningOutcome() == null) {
            return false;
        }
        return true;
    }

    /**
     * Associates the trait to a learningOutcome
     */
    public void wire() {
        getInstance();
        LearningOutcome learningOutcome = learningOutcomeHome.getDefinedInstance();
        if (learningOutcome != null) {
            getInstance().setLearningOutcome(learningOutcome);
        }
    }
}
